<template>
    <div class="addMembers">
        <div class="closeArea" v-show="isFocused" @click="changeFocused"></div>
        <ul>
            <li class="clearfix" v-for="(ite, ind) in overallArr">
                <div class="fl memberList membersLi">
                    <div
                        class="md-field md-theme-default"
                        :class="{ 'md-focused md-highlight': ite[0].value != '' || ite[0].flag }"
                        @click="
                            allFalse();
                            ite[0].flag = true;
                            isFocused = true;
                        "
                    >
                        <!-- <label for="country">{{ ite[0].value ? "角色" : "请选择一个角色" }}</label> -->
                        <div class="md-menu md-select">
                            <input type="text" v-model="ite[0].value" name="country" readonly="readonly" class="md-input md-input md-select-value" />
                            <i class="md-icon md-icon-font md-icon-image md-theme-default" style="position: absolute; top: 0; right: 20px">
                                <svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg">
                                    <path d="M7 10l5 5 5-5z"></path>
                                    <path d="M0 0h24v24H0z" fill="none"></path>
                                </svg>
                            </i>
                        </div>
                    </div>
                    <div class="selectList" v-show="ite[0].flag">
                        <!-- <div class="search">
                            <i class="fa fa-search fa-lg search_icon lmr cur"></i>
                            <input type="text" class="search_input" placeholder="admin" />
                        </div> -->
                        <div class="search_content">
                            <ul class="zeroY">
                                <li v-for="(item, index) in memberList" @click="changeValue(item, 0, ind)">{{ item }}</li>
                            </ul>
                        </div>
                        <!-- <div class="bottom_management">
                            <a href="javascript:;" class="backLink">管理角色</a>
                        </div> -->
                    </div>
                </div>
            </li>
        </ul>
    </div>
</template>

<script>
export default {
    data() {
        return {
            timeFlag: false,
            isFocused: false,
            changeBackgroundColor: false,
            initial: "",
            country: "",
            memberValue: "",
            memberList: ["Orange", "Apple", "Pineapple", "Orange1", "Apple1", "Pineapple1", "Orange2", "Apple2", "Pineapple2", "Orange", "Apple", "Pineapple", "Orange1", "Apple1", "Pineapple1", "Orange2", "Apple2", "Pineapple2"],
            dataList: ["Orange", "Apple", "Pineapple", "Orange1", "Apple1", "Pineapple1", "Orange2", "Apple2", "Pineapple2"],
            singularArr: [
                {
                    value: "",
                    flag: false,
                },
                {
                    value: "",
                    flag: false,
                },
            ],
            overallArr: [
                [
                    {
                        value: "",
                        flag: false,
                    },
                    {
                        value: "",
                        flag: false,
                    },
                ],
            ],
        };
    },
    created() {},
    methods: {
        changeFocused() {
            let that = this;
            that.isFocused = false;
            that.allFalse();
        },
        changeValue(value, index, ind) {
            let that = this;
            let canPush = false;
            that.overallArr[ind][index].flag = false;
            that.overallArr[ind][index].value = value;
            that.isFocused = false;
            //        判断是否允许添加，如果两条/一条信息全部选择，就添加，否则不添加
            for (var i = 0; i < that.overallArr.length; i++) {
                that.overallArr[i][0].value ? (canPush = true) : (canPush = false);
                canPush ? (that.dataList.length == 0 ? "" : that.overallArr[i][1].value ? (canPush = true) : (canPush = false)) : "";
                if (!canPush) {
                    break;
                }
            }
            canPush
                ? that.overallArr.push([
                      {
                          value: "",
                          flag: false,
                      },
                      {
                          value: "",
                          flag: false,
                      },
                  ])
                : "";
        },
        allFalse() {
            let that = this;
            that.overallArr.forEach(function (val, ind) {
                val.forEach(function (value, index) {
                    value.flag = false;
                });
            });
        },
        deleteMember(index) {
            this.overallArr.splice(index, 1);
        },
        reset() {
            this.changeFocused();
        },
    },
};
</script>

<style lang="scss" scoped>
.addMembers {
    margin-top: 10px;
    width: 100%;
    .md-icon.md-theme-default.md-icon-image svg {
        fill: #999;
    }
    ul {
        li {
            margin-bottom: 20px;
            position: relative;
            .trash_icon {
                position: absolute;
                right: -40px;
                top: 28px;
                font-size: 18px;
            }
            .memberList {
                margin-right: 2%;
            }
            .membersLi {
                width: 100%;
                position: relative;
                .selectList {
                    width: 100%;
                    max-height: 403px;
                    background-color: #fff;
                    position: absolute;
                    left: 0;
                    top: 100%;
                    border: 1px solid #e7e7e7;
                    z-index: 7;
                    .search {
                        width: 100%;
                        height: 50px;
                        line-height: 50px;
                        border-bottom: 1px solid #e7e7e7;
                        background-color: #fafafa;
                        padding-left: 20px;
                        .search_input {
                            background-color: #fafafa;
                            height: 20px;
                        }
                    }
                }
                .search_content::-webkit-scrollbar {
                    width: 0;
                }
                .search_content {
                    max-height: 290px;
                    overflow: scroll;
                    margin-bottom: 55px;
                    ul {
                        li {
                            width: 100%;
                            height: 28px;
                            line-height: 28px;
                            transition: 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
                            cursor: pointer;
                            font-size: 13px;
                            padding-left: 15px;
                            margin-bottom: 0;
                            &:hover {
                                background-color: #f7f7f7;
                            }
                        }
                    }
                }
                .bottom_management {
                    border-top: 1px solid #e7e7e7;
                    width: 100%;
                    height: 50px;
                    line-height: 50px;
                    position: absolute;
                    left: 0;
                    bottom: 0;
                    padding-left: 20px;
                }
            }
        }
    }
}
</style>
